<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <title>登录</title>
    <link rel="stylesheet" type="text/css" th:href="@{/static/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/static/css/login.css}"/>
    <style type="text/css">
    </style>
</head>
<body>
<section class="login-bg">
    <div class="login">
        <h1 class="fb">智能门禁系统管理平台</h1>
        <div><img src="../static/img/login_04.png" th:src="@{/static/img/login_04.png}" class="block"></div>
        <form action="" method="post">
            <ul>
                <li>
                    <p>
                        <span><img src="../static/img/login_yhm.png" th:src="@{/static/img/login_yhm.png}"></span>
                        <input type="text" id="userName" autocomplete="off" placeholder="请输入用户名"/>
                    </p>
                </li>
                <li>
                    <p>
                        <span><img src="../static/img/login_mm.png" th:src="@{/static/img/login_mm.png}"></span>
                        <input type="password" id="passWord" autocomplete="off" placeholder="请输入登录密码"/>
                    </p>
                </li>
            </ul>
            <div class="login-btn text-center"><span class="block textCenter white border-radius5 lh50px f18px cursor" id="loginButton">登录</span></div>
        </form>
        <p class="f14px text-center">忘记账号或密码请与系统管理员联系进行处理！</p>
    </div>
</section>

<script src="../static/js/jquery-3.1.1.min.js" th:src="@{/static/js/jquery-3.1.1.min.js}" charset="utf-8"></script>
<script src="../static/layer/layer.js" th:src="@{/static/layer/layer.js}" charset="utf-8"></script>
<script th:inline="javascript">
    var basePath = [[${#request.getContextPath()}]];
    //alert("top.location.href="+top.location.href);
    //alert("location.href="+location.href);
    //避免登录失效后，登录页嵌套到ifream中
    var type = '[[${type}]]';
    // alert(type);
    if (type == 1) {
        top.location.href = basePath + "/login";
    }
    window.onload = function () {
        if (type == 0) {
            if (top.location.href != location.href) {
                top.location.href = basePath + "/login";
            }
        }
        // alert("top.location.href="+top.location.href);
        // alert("location.href="+location.href);

    }


    $(function (e) {
        document.onkeydown = function (e) {
            var theEvent = window.event || e;
            var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
            if (code == 13) {
                login();
            }
        }

        $("span#loginButton").on("click", function (e) {
            login();
        })
    })

    function login() {
        var loginName = $("input#userName").val();
        var passWord = $("input#passWord").val();
        var flag = true;
        if (!loginName) {
            flag = false;
            layer.msg('登录账号不能为空！');
        } else if (!passWord) {
            flag = false;
            layer.msg('登录密码不能为空！');
        }
        if (flag) {
            $.ajax({
                url: basePath + "/login",
                type: "post",
                dataType: "json",
                data: {"userId": loginName, "userPwd": passWord},
                success: function (result) {
                    if (result.code == "200" || result.code == 200) {
                        window.top.location.href = basePath + "/index";
                    } else if (result.code == 2020) {
                        window.top.location.href = basePath + "/updatePwd";
                    } else {
                        layer.msg(result.msg)
                    }
                }
            })
        }
    }
</script>
</body>
</html>


